package com.wx.mythread.sixstatus;

/**
 * 展示线程这三种状态：
 * Blocker
 * Waiting
 * TimerWaiting
 */
public class BlockerWaitingTimerWaiting implements Runnable{


    @Override
    public void run() {
        syn();
    }

    private synchronized void syn(){
        try {
            Thread.sleep(1000);
            wait();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        BlockerWaitingTimerWaiting runable = new BlockerWaitingTimerWaiting();
        Thread thread1 = new Thread(runable);
        thread1.start();
        Thread thread2 = new Thread(runable);
        thread2.start();
        Thread.sleep(5);
        //打印TIMED_WAITING状态，因为正在执行Thread.sleep(1000);
        System.out.println(thread1.getState());
        //打印BLOCKED状态，因为想要拿到synchronize锁拿不到
        System.out.println(thread2.getState());
        Thread.sleep(1300);
        //打印WAITING状态，因为wait()方法，没有被唤醒
        System.out.println(thread1.getState());
    }
}
